home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Bin / DXUtils / Visual Studio 6.0 Wizards / Source Code / Template / dxutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-12  |  8.0 KB  |  178 lines

  1. //-----------------------------------------------------------------------------
  2. // File: DXUtil.h
  3. //
  4. // Desc: Helper functions and typing shortcuts for DirectX programming.
  5. //-----------------------------------------------------------------------------
  6. #ifndef DXUTIL_H
  7. #define DXUTIL_H
  8.  
  9.  
  10. //-----------------------------------------------------------------------------
  11. // Miscellaneous helper functions
  12. //-----------------------------------------------------------------------------
  13. #define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
  14. #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
  15. #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
  16.  
  17.  
  18. #ifndef UNDER_CE
  19. //-----------------------------------------------------------------------------
  20. // Name: DXUtil_GetDXSDKMediaPath() and DXUtil_FindMediaFile() 
  21. // Desc: Returns the DirectX SDK path, as stored in the system registry
  22. //       during the SDK install.
  23. //-----------------------------------------------------------------------------
  24. HRESULT DXUtil_GetDXSDKMediaPathCch( TCHAR* strDest, int cchDest );
  25. HRESULT DXUtil_GetDXSDKMediaPathCb( TCHAR* szDest, int cbDest );
  26. HRESULT DXUtil_FindMediaFileCch( TCHAR* strDestPath, int cchDest, TCHAR* strFilename );
  27. HRESULT DXUtil_FindMediaFileCb( TCHAR* szDestPath, int cbDest, TCHAR* strFilename );
  28. #endif // !UNDER_CE
  29.  
  30.  
  31. //-----------------------------------------------------------------------------
  32. // Name: DXUtil_Read*RegKey() and DXUtil_Write*RegKey()
  33. // Desc: Helper functions to read/write a string registry key 
  34. //-----------------------------------------------------------------------------
  35. HRESULT DXUtil_WriteStringRegKey( HKEY hKey, TCHAR* strRegName, TCHAR* strValue );
  36. HRESULT DXUtil_WriteIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD dwValue );
  37. HRESULT DXUtil_WriteGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID guidValue );
  38. HRESULT DXUtil_WriteBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL bValue );
  39.  
  40. HRESULT DXUtil_ReadStringRegKeyCch( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, DWORD cchDest, TCHAR* strDefault );
  41. HRESULT DXUtil_ReadStringRegKeyCb( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, DWORD cbDest, TCHAR* strDefault );
  42. HRESULT DXUtil_ReadIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD* pdwValue, DWORD dwDefault );
  43. HRESULT DXUtil_ReadGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID* pGuidValue, GUID& guidDefault );
  44. HRESULT DXUtil_ReadBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL* pbValue, BOOL bDefault );
  45.  
  46.  
  47. //-----------------------------------------------------------------------------
  48. // Name: DXUtil_Timer()
  49. // Desc: Performs timer opertations. Use the following commands:
  50. //          TIMER_RESET           - to reset the timer
  51. //          TIMER_START           - to start the timer
  52. //          TIMER_STOP            - to stop (or pause) the timer
  53. //          TIMER_ADVANCE         - to advance the timer by 0.1 seconds
  54. //          TIMER_GETABSOLUTETIME - to get the absolute system time
  55. //          TIMER_GETAPPTIME      - to get the current time
  56. //          TIMER_GETELAPSEDTIME  - to get the time that elapsed between 
  57. //                                  TIMER_GETELAPSEDTIME calls
  58. //-----------------------------------------------------------------------------
  59. enum TIMER_COMMAND { TIMER_RESET, TIMER_START, TIMER_STOP, TIMER_ADVANCE,
  60.                      TIMER_GETABSOLUTETIME, TIMER_GETAPPTIME, TIMER_GETELAPSEDTIME };
  61. FLOAT __stdcall DXUtil_Timer( TIMER_COMMAND command );
  62.  
  63.  
  64. //-----------------------------------------------------------------------------
  65. // UNICODE support for converting between CHAR, TCHAR, and WCHAR strings
  66. //-----------------------------------------------------------------------------
  67. HRESULT DXUtil_ConvertAnsiStringToWideCch( WCHAR* wstrDestination, const CHAR* strSource, int cchDestChar );
  68. HRESULT DXUtil_ConvertWideStringToAnsiCch( CHAR* strDestination, const WCHAR* wstrSource, int cchDestChar );
  69. HRESULT DXUtil_ConvertGenericStringToAnsiCch( CHAR* strDestination, const TCHAR* tstrSource, int cchDestChar );
  70. HRESULT DXUtil_ConvertGenericStringToWideCch( WCHAR* wstrDestination, const TCHAR* tstrSource, int cchDestChar );
  71. HRESULT DXUtil_ConvertAnsiStringToGenericCch( TCHAR* tstrDestination, const CHAR* strSource, int cchDestChar );
  72. HRESULT DXUtil_ConvertWideStringToGenericCch( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar );
  73. HRESULT DXUtil_ConvertAnsiStringToWideCb( WCHAR* wstrDestination, const CHAR* strSource, int cbDestChar );
  74. HRESULT DXUtil_ConvertWideStringToAnsiCb( CHAR* strDestination, const WCHAR* wstrSource, int cbDestChar );
  75. HRESULT DXUtil_ConvertGenericStringToAnsiCb( CHAR* strDestination, const TCHAR* tstrSource, int cbDestChar );
  76. HRESULT DXUtil_ConvertGenericStringToWideCb( WCHAR* wstrDestination, const TCHAR* tstrSource, int cbDestChar );
  77. HRESULT DXUtil_ConvertAnsiStringToGenericCb( TCHAR* tstrDestination, const CHAR* strSource, int cbDestChar );
  78. HRESULT DXUtil_ConvertWideStringToGenericCb( TCHAR* tstrDestination, const WCHAR* wstrSource, int cbDestChar );
  79.  
  80.  
  81. //-----------------------------------------------------------------------------
  82. // Readme functions
  83. //-----------------------------------------------------------------------------
  84. VOID DXUtil_LaunchReadme( HWND hWnd, TCHAR* strLoc = NULL );
  85.  
  86. //-----------------------------------------------------------------------------
  87. // GUID to String converting 
  88. //-----------------------------------------------------------------------------
  89. HRESULT DXUtil_ConvertGUIDToStringCch( const GUID* pGuidSrc, TCHAR* strDest, int cchDestChar );
  90. HRESULT DXUtil_ConvertGUIDToStringCb( const GUID* pGuidSrc, TCHAR* strDest, int cbDestChar );
  91. HRESULT DXUtil_ConvertStringToGUID( const TCHAR* strIn, GUID* pGuidOut );
  92.  
  93.  
  94. //-----------------------------------------------------------------------------
  95. // Debug printing support
  96. // See dxerr9.h for more debug printing support
  97. //-----------------------------------------------------------------------------
  98. VOID    DXUtil_Trace( TCHAR* strMsg, ... );
  99.  
  100. #if defined(DEBUG) | defined(_DEBUG)
  101.     #define DXTRACE           DXUtil_Trace
  102. #else
  103.     #define DXTRACE           sizeof
  104. #endif
  105.  
  106.  
  107. //-----------------------------------------------------------------------------
  108. // Name: ArrayListType
  109. // Desc: Indicates how data should be stored in a CArrayList
  110. //-----------------------------------------------------------------------------
  111. enum ArrayListType
  112. {
  113.     AL_VALUE,       // entry data is copied into the list
  114.     AL_REFERENCE,   // entry pointers are copied into the list
  115. };
  116.  
  117.  
  118. //-----------------------------------------------------------------------------
  119. // Name: CArrayList
  120. // Desc: A growable array
  121. //-----------------------------------------------------------------------------
  122. class CArrayList
  123. {
  124. protected:
  125.     ArrayListType m_ArrayListType;
  126.     void* m_pData;
  127.     UINT m_BytesPerEntry;
  128.     UINT m_NumEntries;
  129.     UINT m_NumEntriesAllocated;
  130.  
  131. public:
  132.     CArrayList( ArrayListType Type, UINT BytesPerEntry = 0 );
  133.     ~CArrayList( void );
  134.     HRESULT Add( void* pEntry );
  135.     void Remove( UINT Entry );
  136.     void* GetPtr( UINT Entry );
  137.     UINT Count( void ) { return m_NumEntries; }
  138.     bool Contains( void* pEntryData );
  139.     void Clear( void ) { m_NumEntries = 0; }
  140. };
  141.  
  142. //-----------------------------------------------------------------------------
  143. // WinCE build support
  144. //-----------------------------------------------------------------------------
  145.  
  146. #ifdef UNDER_CE
  147.  
  148. #define CheckDlgButton(hdialog, id, state) ::SendMessage(::GetDlgItem(hdialog, id), BM_SETCHECK, state, 0)
  149. #define IsDlgButtonChecked(hdialog, id) ::SendMessage(::GetDlgItem(hdialog, id), BM_GETCHECK, 0L, 0L)
  150. #define GETTIMESTAMP GetTickCount
  151. #define _TWINCE(x) _T(x)
  152.  
  153. __inline int GetScrollPos(HWND hWnd, int nBar)
  154. {
  155.     SCROLLINFO si;
  156.     memset(&si, 0, sizeof(si));
  157.     si.cbSize = sizeof(si);
  158.     si.fMask = SIF_POS;
  159.     if (!GetScrollInfo(hWnd, nBar, &si))
  160.     {
  161.         return 0;
  162.     }
  163.     else
  164.     {
  165.         return si.nPos;
  166.     }
  167. }
  168.  
  169. #else // !UNDER_CE
  170.  
  171. #define GETTIMESTAMP timeGetTime
  172. #define _TWINCE(x) x
  173.  
  174. #endif // UNDER_CE
  175.  
  176.  
  177. #endif // DXUTIL_H
  178.